package com.myjava.linkedhashset;

import java.util.LinkedHashSet;
import java.util.Objects;

class Person{
    String name;
    int age;
  public   Person(String name, int age){
        this.name=name;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Person)) return false;

        Person person = (Person) o;

        if (age != person.age) return false;
        return name.equals(person.name);
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + age;
        return result;
    }
}



public class LinkedhashsetClass {


    public static void main(String[] args) {
        LinkedHashSet<String> st = new LinkedHashSet<>();
        st.add("a");
        st.add("b");
        st.add("2");
        st.add("a");
        st.add("1");
        System.out.println(st);
        LinkedHashSet<Person> pp = new LinkedHashSet<>();
        Person p1 = new Person("ws", 18);
        Person p2 = new Person("wf", 18);
        Person p3 = new Person("ws", 19);
        pp.add(p1);
        pp.add(p2);
        pp.add(p3);
        System.out.println(pp);

    }

}
